﻿Imports System.Data.OleDb
Public Class SinonimosPSIs

    Private Sub btn_SINONIMOS_Volver_Topicos_PSIs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SINONIMOS_Volver_PSIs.Click
        Me.Close()
    End Sub

    Private Sub btn_SINONIMOS_Añadir_SINÓNIMOS_TOPICOS_PSIS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SINÓNIMOS_PSIS.Click
        Dim nuevo_sinonimo As String
        nuevo_sinonimo = InputBox("Teclea el nombre para el nuevo sinónimo:", "Añadir Sinónimo")
        If nuevo_sinonimo = "" Then
            MsgBox("No has introducido el nombre de ningún sinónimo. Inténtalo de nuevo", , "SINÓNIMO EN BLANCO")
            Exit Sub
        End If
        lsb_SINONIMOS_PSIS.Items.Add(nuevo_sinonimo)

        '==============================================================================================
        'COMENTARIOS. AÑADIR UN SINOMIMO DEL OBJETO EN LA B.D.
        '==============================================================================================

        'Se establece la conexión con la base de datos.
        Dim sCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & txtBase
        Dim ODbConn As New OleDb.OleDbConnection(sCnn)
        ODbConn.Open()

        'Se crea un objeto Command 
        'Se ejecuta una consulta de actualización que graba el Nombre del Juego
        Dim LACommand As New OleDb.OleDbCommand("INSERT INTO SINONIMOS_PSI (psi, sinonimo) values (" & "'" & txt_SINONIMOS_PSIS.Text & "'" & "," & "'" & nuevo_sinonimo & "'" & ")", ODbConn)
        Dim LADataReader As OleDbDataReader = LACommand.ExecuteReader(CommandBehavior.CloseConnection)

        'Libera memoria
        LACommand.Dispose()
        ODbConn.Close()

    End Sub

    Private Sub btn_SINONIMOS_Eliminar_Topicos_psis_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SINONIMOS_Eliminar_psis.Click
        '==============================================================================================
        'COMENTARIOS. ELIMINAR UN SINOMIMO DEL OBJETO EN LA B.D.
        '==============================================================================================

        Dim sCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & txtBase
        Dim ODbConn As New OleDb.OleDbConnection(sCnn)
        ODbConn.Open()

        Dim SinonimosCommand As New OleDb.OleDbCommand("DELETE FROM SINONIMOS_PSI WHERE SINONIMOS_PSI.sinonimo= " & "'" & lsb_SINONIMOS_PSIS.SelectedItem & "'" & " and " & "SINONIMOS_PSI.psi= " & "'" & txt_SINONIMOS_PSIS.Text & "'", ODbConn)
        Dim SinonimosDataReader As OleDb.OleDbDataReader = SinonimosCommand.ExecuteReader(CommandBehavior.CloseConnection)

        lsb_SINONIMOS_PSIS.Items.Remove(lsb_SINONIMOS_PSIS.SelectedItem)
        SinonimosCommand.Dispose()
        ODbConn.Close()

        lsb_SINONIMOS_PSIS.Items.Remove(lsb_SINONIMOS_PSIS.SelectedItem)
    End Sub

    Private Sub SinonimosPSIs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub SinonimosPSIs_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
        btn_SINÓNIMOS_PSIS.Focus()
    End Sub
End Class